package nc.nc_xiuxian;

import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import static nc.nc_xiuxian.NC_XIUXIAN.plugin;

//总的属性境界读取操作文档

public class JINGJIE {
    public static void playerlistload() throws IOException {
        File file = new File(plugin.getDataFolder(),"playerlist.yml");
        YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
        if(!file.exists()){
            file.createNewFile();
            return;
        }
        plugin.playerlist.addAll(yml.getStringList("list")); //玩家读取
        for(String s:plugin.playerlist){
            jjfile(s); //境界读取
            SHUXING.SHUXINGLOAD(s);//属性读取
        }
    }
    public static void playerlistadd(Player player) throws IOException {
        File file = new File(plugin.getDataFolder(),"playerlist.yml");
        YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
        List<String>list=new ArrayList<>();
        if(!file.exists()){
            file.createNewFile();
            list.add(player.getName());
            yml.set("list",list);
            yml.save(file);
            plugin.playerlist=yml.getStringList("list");
            playerlistload();
            return;
        }
        list=yml.getStringList("list");
        if(!list.contains(player.getName())){
            list.add(player.getName());
            yml.set("list",list);
            yml.save(file);
            plugin.playerlist=yml.getStringList("list");
            playerlistload();
        }
    }
    public static void jjfile(String playername) throws IOException {
        File file = new File(plugin.getDataFolder(),"JINGJIE.yml");
        YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
        if(!file.exists()){
            file.createNewFile();
            yml.set(playername,"凡人");
            yml.save(file);
            plugin.playerjj.put(playername,"凡人");
            return;
        }
        for(String s: yml.getKeys(false)){
            plugin.playerjj.put(s,yml.getString(s));
        }
        if(yml.getString(playername)==null){
            plugin.playerjj.put(playername,"凡人");
        }
    }
    public static void jjset(String playername,String jj) throws IOException {
        File file = new File(plugin.getDataFolder(),"JINGJIE.yml");
        YamlConfiguration yml = YamlConfiguration.loadConfiguration(file);
        if(!file.exists()){
            file.createNewFile();
            yml.set(playername,"凡人");
            yml.save(file);
            plugin.playerjj.put(playername,"凡人");
            return;
        }
        for(String s: yml.getKeys(false)){
            plugin.playerjj.put(s,yml.getString(s));
        }
        plugin.playerjj.put(playername,jj);
        for(String s:plugin.playerjj.keySet()){
            yml.set(s,plugin.playerjj.get(s));
        }
        yml.save(file);
    }
    public static void jjupdata(Player player,double jj) throws IOException {
        double xjj=SHUXING.sxloadapi(player,"xjj");
        List<String>jjlist=plugin.getConfig().getStringList("境界划分");
        switch ((int) jj){
            case 0:
                switch ((int) xjj){
                    case 0:
                        jjset(player.getName(),jjlist.get((int) jj)+"一层");
                        SHUXING.sxsetadd(player,"xjj",1.0);
                        break;
                    case 1:
                        jjset(player.getName(),jjlist.get((int) jj)+"二层");
                        SHUXING.sxsetadd(player,"xjj",1.0);
                        break;
                    case 2:
                        jjset(player.getName(),jjlist.get((int) jj)+"三层");
                        SHUXING.sxsetadd(player,"xjj",1.0);
                        break;
                    case 3:
                        jjset(player.getName(),jjlist.get((int) jj)+"四层");
                        SHUXING.sxsetadd(player,"xjj",1.0);
                        break;
                    case 4:
                        jjset(player.getName(),jjlist.get((int) jj)+"五层");
                        SHUXING.sxsetadd(player,"xjj",1.0);
                        break;
                    case 5:
                        jjset(player.getName(),jjlist.get((int) jj)+"六层");
                        SHUXING.sxsetadd(player,"xjj",1.0);
                        break;
                    case 6:
                        jjset(player.getName(),jjlist.get((int) jj)+"七层");
                        SHUXING.sxsetadd(player,"xjj",1.0);
                        break;
                    case 7:
                        jjset(player.getName(),jjlist.get((int) jj)+"八层");
                        SHUXING.sxsetadd(player,"xjj",1.0);
                        break;
                    case 8:
                        jjset(player.getName(),jjlist.get((int) jj)+"九层");
                        SHUXING.sxsetadd(player,"xjj",1.0);
                        break;
                    case 9:
                        jjset(player.getName(),jjlist.get((int) jj)+"圆满");
                        SHUXING.sxsetadd(player,"xjj",1.0);
                        break;
                }
                break;
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
                switch ((int) xjj){
                    case 0:
                        jjset(player.getName(),jjlist.get((int) jj)+"初期");
                        SHUXING.sxsetadd(player,"xjj",1.0);
                        break;
                    case 1:
                        jjset(player.getName(),jjlist.get((int) jj)+"中期");
                        SHUXING.sxsetadd(player,"xjj",1.0);
                        break;
                    case 2:
                        jjset(player.getName(),jjlist.get((int) jj)+"后期");
                        SHUXING.sxsetadd(player,"xjj",1.0);
                        break;
                    case 3:
                        jjset(player.getName(),jjlist.get((int) jj)+"巅峰");
                        SHUXING.sxsetadd(player,"xjj",1.0);
                        break;
                }
                break;
        }
    }
}
